package org.dppc.contact.m8;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.List;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("ContactTable")
public class ContactTable {
	@XStreamImplicit
	private List<Contact> contacts;

	public ContactTable(List<Contact> contacts) {
		super();
		this.contacts = contacts;
	}

	public List<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(List<Contact> contacts) {
		this.contacts = contacts;
	}
	
	public ContactTable() {
		super();
		// TODO Auto-generated constructor stub
	}

	public static void main(String[] args){
		XStream xStream = new XStream();
		xStream.processAnnotations(new Class[]{ContactTable.class,Contact.class,PhoneElement.class,EmailElement.class,IMElement.class,MsnElement.class,WebPageElement.class,AddressElement.class});
		try {
			
			ContactTable table = (ContactTable) xStream.fromXML(new InputStreamReader((new BufferedInputStream(new FileInputStream(new File("D:" + File.separator+ "Contact.xml")))),Charset.forName("UTF-8")));
			System.out.println(table.getContacts().size());
			System.out.println(table.getContacts().get(0).getFileAs());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
